classdef dotsDrawable < dotsAllManagedObjects
    % @class dotsDrawable
    % Superclass for drawable graphics objects
    
    properties (SetObservable = true)
        % true or false, whether to draw() this object.
        isVisible;
        
        % a foreground color, [L] [LA] [RGB] [RGBA], 0-255
        % @details
        % Automatically opts in to share via dotsTheSwitchboard.
        foregroundColor;
        
        % a background color, [L] [LA] [RGB] [RGBA], 0-255
        % @details
        % Automatically opts in to share via dotsTheSwitchboard.
        backgroundColor;
    end
    
    properties (SetObservable = false)
        % Psychtoolbox Scxreen index of the current drawing window
        % @details
        % Automatically opts in to share via dotsTheSwitchboard.
        windowNumber;
        
        % pixel dimensions of the current drawing window [x y x2 y2]
        % @details
        % Automatically opts in to share via dotsTheSwitchboard.
        windowRect;
        
        % Hz frame rate of the current drawing window
        % @details
        % Automatically opts in to share via dotsTheSwitchboard.
        windowFrameRate;
        
        % degrees-to-pixels factor for the current drawing window
        % @details
        % Automatically opts in to share via dotsTheSwitchboard.
        pixelsPerDegree;

        % system path to locate image files
        % Use dotsTheMachineConfiguration to specify a machine-specific
        % imagesPath.
        imagesPath;
    end
    
    methods
        function self = dotsDrawable
            self = self@dotsAllManagedObjects;
            
            % set machine-specific and other defaults
            dotsTheMachineConfiguration.applySettingsToObject(self);

            % share drawing-related properties
            self.isVisible = true;
            dotsTheSwitchboard.sharePropertyOfObject('isVisible', self);
            dotsTheSwitchboard.sharePropertyOfObject('foregroundColor', self);
            dotsTheSwitchboard.sharePropertyOfObject('backgroundColor', self);
            
            % shared some screen properties
            theScreen = dotsTheScreen.theObject;
            dotsTheSwitchboard.shareManyPropertiesOfObject( ...
                theScreen.sharedProperties, self);
        end
        
        % do any pre-draw setup that requires an open window
        function prepareToDrawInWindow(self)
        end

        % draw() or not, depending on isVisible and possibly other factors
        function mayDrawNow(self)
            if self.isVisible
                self.draw;
            end
        end

        % subclass must redefine draw()
        function draw(self)
        end
        
        % shorthand for isVisible=true
        function show(self)
            self.isVisible = true;
        end

        % shorthand for isVisible=false
        function hide(self)
            self.isVisible = false;
        end
    end
end